<?php

namespace app\admin\controller;

use app\common\controller\Backend;

/**
 * 扫码记录管理
 *
 * @icon fa fa-circle-o
 */
class Scan extends Backend
{

    /**
     * Scan模型对象
     * @var \app\common\model\Scan
     */
    protected $model = null;

    public function _initialize()
    {
        parent::_initialize();
        $this->model = new \app\common\model\Scan;
        $this->view->assign("typeDataList", $this->model->getTypeDataList());

    }

    /**
     * 查看
     */
    public function index()
    {
        //当前是否为关联查询
        $this->relationSearch = false;
        //设置过滤方法
        $this->request->filter(['strip_tags', 'trim']);
        if ($this->request->isAjax()) {
            //如果发送的来源是Selectpage，则转发到Selectpage
            if ($this->request->request('keyField')) {
                return $this->selectpage();
            }
            list($where, $sort, $order, $offset, $limit) = $this->buildparams();

            $list = $this->model

                ->where($where)
                ->order($sort, $order)
                ->paginate($limit);

            foreach ($list as $row) {
                $row->visible(['id','connection_name','connection_mobile','connection_mobile_see','connection_mobile_two','connection_mobile_two_see','staff_name','staff_mobile','canal_name','canal_mobile','createtime','type_data','staff_ibec_name']);

            }

            $result = array("total" => $list->total(), "rows" => $list->items());

            return json($result);
        }
        return $this->view->fetch();
    }
    /**
     * 详情
     */
    public function see($id){
        $row = $this->model->with(['dynatown'=>function($query){
            $query->withField('id,name');
        }])->where(["scan.id"=>$id])->find();
        if (!$row) {
            $this->error(__('No Results were found'));
        }
        $this->assign("row",$row);
        return $this->view->fetch();
    }
}
